package com.cqupt.controller;

import com.cqupt.model.pojo.AllWord;
import com.cqupt.model.pojo.Word;
import com.cqupt.model.vo.ExampleVO;
import com.cqupt.model.vo.Result;
import com.cqupt.model.vo.ResultCodeEnum;
import com.cqupt.model.vo.SpeakVO;
import com.cqupt.service.AllWordService;
import com.cqupt.service.UserWordService;
import com.cqupt.service.WordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/word")
@Tag(name = "背诵单词模块")
public class WordController {
    @Resource
    private WordService wordService;

    @Resource
    private UserWordService userWordService;

    @Resource
    private AllWordService allWordService;

//    @GetMapping("/recite")
//    @Operation(summary = "每日背单词接口")
//    public Result recite(@RequestParam int booId) {
//        List<Word> wordList = wordService.recite(booId);
//        return Result.build(wordList, ResultCodeEnum.SUCCESS);
//    }
//
//    @GetMapping("/learn")
//    @Operation(summary = "学习单词")
//    public Result learn(@RequestParam int wordId, @RequestParam int bookId) {
//        userWordService.learn(wordId, bookId);
//        return Result.build(null, ResultCodeEnum.SUCCESS);
//    }


    @GetMapping("/queryLike")
    @Operation(summary = "查询单词")
    public Result queryLike(@RequestParam String word) {
        List<AllWord> list = allWordService.queryLike(word);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/queryByWord")
    @Operation(summary = "根据单词查询是否已经被收藏")
    public Result queryByWord(@RequestParam String word) {
        Integer res = wordService.queryByWord(word);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/index")
    @Operation(summary = "显示未学单词个数，需要复习单词个数")
    public Result index(@RequestParam int bookId) {
        Map<String, Integer> map = wordService.index(bookId);
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/learn")
    @Operation(summary = "开始背诵单词")
    public Result learn(@RequestParam int bookId,@RequestParam int count) {
        List<Word> list = wordService.learn(bookId,count);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/known")
    @Operation(summary = "认识该单词")
    public Result known(@RequestParam int bookId, @RequestParam int wordId) {
        wordService.known(bookId, wordId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/forget")
    @Operation(summary = "忘记该单词")
    public Result forget(@RequestParam int bookId, @RequestParam int wordId) {
        wordService.forget(bookId, wordId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/review")
    @Operation(summary = "复习单词")
    public Result review(@RequestParam int bookId) {
        List<Word> list = wordService.review(bookId);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/example")
    @Operation(summary = "根据单词生成例句")
    public Result example(@RequestParam String word) {
        SpeakVO res = wordService.example(word);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/example2")
    @Operation(summary = "调用外部接口生成例句")
    public Result example2(@RequestParam String word) {
        List<ExampleVO> res = wordService.example2(word);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/page")
    @Operation(summary = "查看所有单词(分页)")
    public Result getByPage(@RequestParam int bookId, @RequestParam int pageNum) {
        List<Word> list = wordService.getByPage(bookId, pageNum);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getWord")
    @Operation(summary = "查找单词")
    public Result getWord(@RequestParam int bookId, @RequestParam String word) {
        List<Word> list = wordService.getWord(bookId, word);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


}
